package cpre556.project2.eclipsePlugin.support;

/**
 * @author Josh, Eric
 */

import java.util.Vector;

public class VulnerabilitySorter{
	private Vector<Vulnerability> sortedVulnerabilityList;
	private int index;
	
	/**
	 * Constructor
	 */
	public VulnerabilitySorter(){
		sortedVulnerabilityList = new Vector<Vulnerability>();
		index = -1;
	}	
	
	/**
	 * Sorts a list of vulnerabilities
	 * @param unsortedVulnerabilityList Vector<Vulnerability>
	 * @return Vector<Vulnerability>
	 */
	public Vector<Vulnerability> sortByLineNumber(Vector<Vulnerability> unsortedVulnerabilityList){
		while(!unsortedVulnerabilityList.isEmpty()){
			int min = 9999;
			int cur = 0;
			int size = unsortedVulnerabilityList.size();
			
			if(size >= 1){
				min = unsortedVulnerabilityList.get(0).getLineNumber();
				index = 0;
			}
			
			for(int i = 0; i < size; i++){
				cur = unsortedVulnerabilityList.get(i).getLineNumber();
				
				if(cur < min){
					index = i;
					min = cur;
				}
			}
			
			sortedVulnerabilityList.add(unsortedVulnerabilityList.get(index));
			unsortedVulnerabilityList.remove(index);			
		}
		
		return sortedVulnerabilityList;
	}
}
